package com.valentinalee.bms.web.servlet.manager;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.valentinalee.bms.service.ManagerService;
import com.valentinalee.bms.service.impl.ManagerServiceImpl;

public class RegisterManagerServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		req.setCharacterEncoding("gbk");
		resp.setCharacterEncoding("gbk");
		
		//	1.从页面获取相关参数
		String name = req.getParameter("cname");
		if(null==name||"".equals(name)){
			resp.getWriter().write("姓名不能为空");
		}
		
		String account = req.getParameter("caccount");
		if(null==account||"".equals(account)){
			resp.getWriter().write("账号不能为空");
		}
		
		String password = req.getParameter("cpassword");
		if(null==password||"".equals(password)){
			resp.getWriter().write("密码不能为空");
		}
		
		//2.把相关参数传到service层
		ManagerService service=new ManagerServiceImpl();
		service.RegisterManager(name, account, password);
		
		//3.返回页面结果
		
		resp.getWriter().write("注册成功!!!");
	}
	
	

}
